<?php
include dirname(__FILE__) . "/config/functions.php";

$optionsQuery = mysql_query("SELECT * FROM `option`");
while($row = mysql_fetch_assoc($optionsQuery))    $options[$row['key']] = $row['value'];


if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['username']) && isset($_GET['hash'])) {

    $username = mysql_real_escape_string($_GET['username']);
    $hash = mysql_real_escape_string($_GET['hash']); // Set hash variable  

    if ($hash == '') {

        header("location:index.php");
        return;
    }

    $search = mysql_query("SELECT * FROM user WHERE username='" . $username . "' AND hash='" . $hash . "' AND status='0'") or die(mysql_error());
    $user = mysql_fetch_array($search);

    if (mysql_num_rows($search) > 0) {

        mysql_query("UPDATE user SET status='1', hash='' WHERE Username='" . $username . "' AND hash='" . $hash . "' AND status='0'") or die(mysql_error());

        //get all options
        $options = mysql_query("SELECT * FROM `option`");
        $allOprionsArray = array();
        while ($option = mysql_fetch_array($options)) {
            $allOprionsArray[$option['key']] = $option['value'];
        }
        //send email
        $result = mysql_query("SELECT * from mail_template WHERE code='welcome_email'");
        $mailTemplate = mysql_fetch_array($result);
        $search = array('{name}', '{username}', '{password}', '{email}', '{sitename}', '{siteurl}');
        $replace = array($user['name'], $user['username'], $user['password'], $user['email'], $allOprionsArray['site_name'], $allOprionsArray['site_url']);
        $body = str_replace($search, $replace, $mailTemplate['body']);
        $subject = str_replace($search, $replace, $mailTemplate['subject']);
        sendMail($user['email'], $subject, $body);
    } else {
        echo "Invalid request logging";
        exit(0);
    }
} else {
    echo "Invalid request logging";
    exit(0);
}
?>

<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title><?= $options['site_name'] ?></title>
        <meta property="og:title" content="<?= $options['site_name'] ?>">
        <meta property="og:site_name" content="<?= $options['site_name'] ?>">
        <meta property="og:type" content="<?= $options['type'] ?>">
        <meta property="og:url" content="<?= $options['url'] ?>">
        <meta property="og:image" content="<?= $options['image'] ?>">
        <meta property="fb:admins" content="<?= $options['admins'] ?>">
        <meta name="description" content="<?= $options['site_description'] ?>">
        <meta name="keywords" content="<?= $options['keywords'] ?>">
        <meta name="author" content="<?= $options['author'] ?>">
        <meta name="Robots" content="<?= $options['Robots'] ?>">
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
        <link href="css/bootstrap.min.css" rel="stylesheet"/>
        <link href="css/style.css" rel="stylesheet"/>
    </head>
    <body>

        <table width="950" height="1" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
            <tr>
                <td background="images/bg.png">
                    <img src="images/header.png" alt="Viral Marketing Script - Your MEGA Traffic on Over-Drive!" width="950" height="294" lowsrc="Viral Marketing Script - Your MEGA Traffic on Over-Drive!"></td>
            </tr>
            <tr>
                <td background="images/bg.png"><div align="center"><strong><span class="style4">
                                :: <a href="index.php">Home</a> 
                                :: <a href="contact.php">Contact Us</a> 
                                :: <a href="advertise.php">Advertise</a> 
                                :: <a href="member/login.php">Login</a> 
                                ::</span></strong></div>
                </td>
            </tr>
            <tr>
                <td background="images/bg.png">
                    <div align="center">

                        <div class="container"> 
                            <div style="margin: 7px;"> 
                                <?php $_position = 'top'; ?>
                                <?php include dirname(__FILE__) . '/_banner.php'; ?>
                            </div>
                            <div class="row">


                                <div class="main text-center">
                                    <p style="font-weight: bold; font-size: 21px; padding: 43px;">
                                        Thank You for activating your account.<br>
                                        Now just login to your account and start using our service.
                                    </p>
                                </div>
                            </div> 
                            <div style="margin: 35px;"> 
                                <?php $_position = 'bottom'; ?>
                                <?php include dirname(__FILE__) . '/_banner.php'; ?>
                            </div>
                        </div>

                    </div>
                </td>
            </tr>
            <tr>
                <td background="images/bg.png"><div align="center">
                        <?php include 'footer.php'; ?>
                    </div></td>
            </tr>
            <tr>
                <td>
                    <img src="images/footer.png" width="950" height="108" alt=""></td>
            </tr>
        </table>
        <script src="js/jquery-1.10.2.min.js"></script>
        <script src="js/bootstrap.min.js"></script>

        <!-- End Save for Web Slices -->
    </body>
</html>